package com.ncst.backend.controller;

import com.ncst.backend.common.Result;
import com.ncst.backend.domain.DisposalRequest;
import com.ncst.backend.service.DisposalRequestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处置申请控制器
 */
@Api(tags = "处置申请管理")
@Slf4j
@RestController
@RequestMapping("/disposal-requests")
public class DisposalRequestController {

    @Autowired
    private DisposalRequestService disposalRequestService;

    /** 查询所有处置申请 */
    @ApiOperation("查询所有处置申请")
    @GetMapping
    public Result<List<DisposalRequest>> getAll() {
        log.info("查询所有处置申请");
        List<DisposalRequest> list = disposalRequestService.getAll();
        return Result.success(list);
    }

    /** 按条件查询处置申请列表 */
    @ApiOperation("按条件查询处置申请列表")
    @PostMapping("/search")
    public Result<List<DisposalRequest>> getByCondition(@ApiParam("查询条件") @RequestBody DisposalRequest disposalRequest) {
        log.info("按条件查询处置申请: {}", disposalRequest);
        List<DisposalRequest> list = disposalRequestService.getByCondition(disposalRequest);
        return Result.success(list);
    }

    /** 新增处置申请 */
    @ApiOperation("新增处置申请")
    @PostMapping
    public Result<Void> save(@ApiParam("处置信息") @RequestBody DisposalRequest disposalRequest) {
        log.info("新增处置申请: {}", disposalRequest);
        boolean success = disposalRequestService.save(disposalRequest);
        return success ? Result.success("新增成功") : Result.error("新增失败");
    }

    /** 更新处置申请 */
    @ApiOperation("更新处置申请")
    @PutMapping("/{id}")
    public Result<Void> updateById(@ApiParam("处置ID") @PathVariable Integer id, @ApiParam("处置信息") @RequestBody DisposalRequest disposalRequest) {
        log.info("更新处置申请: id={}, disposalRequest={}", id, disposalRequest);
        disposalRequest.setId(id);
        boolean success = disposalRequestService.updateById(disposalRequest);
        return success ? Result.success("更新成功") : Result.error("更新失败");
    }

    /** 删除处置申请 */
    @ApiOperation("删除处置申请")
    @DeleteMapping("/{id}")
    public Result<Void> removeById(@ApiParam("处置ID") @PathVariable Integer id) {
        log.info("删除处置申请: {}", id);
        boolean success = disposalRequestService.removeById(id);
        return success ? Result.success("删除成功") : Result.error("删除失败");
    }

    /** 批量删除处置申请 */
    @ApiOperation("批量删除处置申请")
    @DeleteMapping("/batch")
    public Result<Void> removeByIds(@ApiParam("处置ID列表") @RequestBody List<Integer> ids) {
        log.info("批量删除处置申请: {}", ids);
        boolean success = disposalRequestService.removeByIds(ids);
        return success ? Result.success("批量删除成功") : Result.error("批量删除失败");
    }

    /** 通过registerId查询处置申请 */
    @ApiOperation("通过挂号ID查询处置申请")
    @GetMapping("/register/{registerId}")
    public Result<List<DisposalRequest>> getByRegisterId(@ApiParam("挂号ID") @PathVariable Integer registerId) {
        log.info("通过挂号ID查询处置申请: {}", registerId);
        List<DisposalRequest> list = disposalRequestService.getByRegisterId(registerId);
        return Result.success(list);
    }
}
